package com.wh1200.mybatis.xmlless.model.base

import com.wh1200.kotlin.toUnderlineCase
import com.wh1200.mybatis.xmlless.model.ObjectJoinInfo
import com.wh1200.mybatis.xmlless.model.TableName
import com.wh1200.mybatis.xmlless.model.XmllessTableInfo

/**
 *
 * @author 吴昊
 * @date 2024/1/22 18:27
 * @since v4.0.0
 * @version 1.0
 */
interface BaseJoinObjectProvider {

  /**
   * @return
   */
  fun resolve(): ObjectJoinInfo

  fun getAlias(): String

  /**
   * @param joinOnThisProperty
   * @param tableInfo
   * @return
   */
  fun resolveJoinTableName(
      joinOnThisProperty: String,
      alias: String,
      tableInfo: XmllessTableInfo
  ): TableName {
    if (alias.isNotBlank()) {
      return TableName.resolveWithPrefix(tableInfo.tableName, alias, false)
    } else {
      val prefix = joinOnThisProperty.toUnderlineCase().lowercase() + "_"
      return TableName.resolveWithPrefix(tableInfo.tableName, prefix)
    }
  }

}
